const multer = require('@koa/multer')
console.log('🚀 ~ multer:', multer)
const path = require('path')
//配置storage
var storage = multer.diskStorage({
    //文件保存路径
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname, '../uploads/images')) //路径一定要对
    },
    //修改文件名称
    filename: function (req, file, cb) {
        console.log('🚀 ~ file:', file)
        var fileFormat = file.originalname.split('.')
        cb(null, Date.now() + '.' + fileFormat[fileFormat.length - 1])
    }
})
//文件上传限制
const limits = {
    fields: 10, //非文件字段的数量
    fileSize: 12 * 500 * 1024, //单位 b
    files: 1 //文件数量
}

//加载配置

module.exports = multer({ storage, limits })
